﻿using UnityEngine;
using System.Collections;


/// <summary>
/// 플레이어 캐릭터를 조종하는 컴포넌트
/// </summary>
public class PlayerController : BaseController
{
	// Members

	//bool			m_isMoving;								// 캐릭터 이동중 플래그


	protected override void OnUpdate ()
	{
		//base.OnUpdate ();

		BaseCharacter.Direction oldDir	= character.currentDirection;
		BaseCharacter.Direction newDir	= BaseCharacter.Direction.None;

		if(Input.GetKeyDown(KeyCode.LeftArrow))				// * 왼쪽/오른쪽 방향 전환
		{
			newDir		= BaseCharacter.Direction.Left;
			moving		= true;
		}
		else if(Input.GetKeyDown(KeyCode.RightArrow))
		{
			newDir		= BaseCharacter.Direction.Right;
			moving		= true;
		}

		if(newDir != BaseCharacter.Direction.None && newDir != oldDir)	// * 예전이랑 방향이 바뀐 경우만 방향 변경
		{
			character.currentDirection	= newDir;
		}

		//if(Input.GetKeyUp(KeyCode.LeftArrow) || Input.GetKeyUp(KeyCode.RightArrow))
		if(!Input.GetKey(KeyCode.LeftArrow) && !Input.GetKey(KeyCode.RightArrow))
		{
			moving		= false;
		}


		if(		Input.GetKey(KeyCode.LeftShift)
		   ||	Input.GetKey(KeyCode.Z))					// * 점프
		{
			character.Jump();
		}

		if(Input.GetKeyDown(KeyCode.Space)
		   || Input.GetKeyDown(KeyCode.X))					// * 뿅뿅
		{
			character.Shoot();
		}
	}
}
